<?php
// +----------------------------------------------------------------------
// * Created by PhpStorm.
// +----------------------------------------------------------------------
// * Author: D H
// +----------------------------------------------------------------------
// * Date: 2017/9/4
// +----------------------------------------------------------------------
// * Time: 12:24
// +----------------------------------------------------------------------
namespace app\api\logic;

use think\log;
use think\Request;
use think\Validate;
use tool\Common;

class Base
{
    protected $data = [];
    public function init($data = [])
    {
        $this->data = $data;
        //Log::info('参数开始');
        //Log::info(Request::instance()->url());
        //Log::info(json_encode($data));
        //Log::info('参数结束');
        return $this;
    }

    //验证规则
    protected function check($method = '')
    {
        $class = str_replace('logic', 'validate', get_called_class());
        $validateRule = $class::$method();
        $validate = new Validate($validateRule['rule'], $validateRule['msg']);
        if (!$validate->check($this->data)) {
            return Common::rm(-1, $validate->getError());
        }

        return Common::rm(1, '验证通过');
    }

}